home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / var / lib / python-support / python2.6 / gdata / tlslite / errors.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-04-20  |  7.3 KB  |  169 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. '''Exception classes.
  5. @sort: TLSError, TLSAbruptCloseError, TLSAlert, TLSLocalAlert, TLSRemoteAlert,
  6. TLSAuthenticationError, TLSNoAuthenticationError, TLSAuthenticationTypeError,
  7. TLSFingerprintError, TLSAuthorizationError, TLSValidationError, TLSFaultError
  8. '''
  9. from constants import AlertDescription, AlertLevel
  10.  
  11. class TLSError(Exception):
  12.     '''Base class for all TLS Lite exceptions.'''
  13.     pass
  14.  
  15.  
  16. class TLSAbruptCloseError(TLSError):
  17.     '''The socket was closed without a proper TLS shutdown.
  18.  
  19.     The TLS specification mandates that an alert of some sort
  20.     must be sent before the underlying socket is closed.  If the socket
  21.     is closed without this, it could signify that an attacker is trying
  22.     to truncate the connection.  It could also signify a misbehaving
  23.     TLS implementation, or a random network failure.
  24.     '''
  25.     pass
  26.  
  27.  
  28. class TLSAlert(TLSError):
  29.     '''A TLS alert has been signalled.'''
  30.     _descriptionStr = {
  31.         AlertDescription.close_notify: 'close_notify',
  32.         AlertDescription.unexpected_message: 'unexpected_message',
  33.         AlertDescription.bad_record_mac: 'bad_record_mac',
  34.         AlertDescription.decryption_failed: 'decryption_failed',
  35.         AlertDescription.record_overflow: 'record_overflow',
  36.         AlertDescription.decompression_failure: 'decompression_failure',
  37.         AlertDescription.handshake_failure: 'handshake_failure',
  38.         AlertDescription.no_certificate: 'no certificate',
  39.         AlertDescription.bad_certificate: 'bad_certificate',
  40.         AlertDescription.unsupported_certificate: 'unsupported_certificate',
  41.         AlertDescription.certificate_revoked: 'certificate_revoked',
  42.         AlertDescription.certificate_expired: 'certificate_expired',
  43.         AlertDescription.certificate_unknown: 'certificate_unknown',
  44.         AlertDescription.illegal_parameter: 'illegal_parameter',
  45.         AlertDescription.unknown_ca: 'unknown_ca',
  46.         AlertDescription.access_denied: 'access_denied',
  47.         AlertDescription.decode_error: 'decode_error',
  48.         AlertDescription.decrypt_error: 'decrypt_error',
  49.         AlertDescription.export_restriction: 'export_restriction',
  50.         AlertDescription.protocol_version: 'protocol_version',
  51.         AlertDescription.insufficient_security: 'insufficient_security',
  52.         AlertDescription.internal_error: 'internal_error',
  53.         AlertDescription.user_canceled: 'user_canceled',
  54.         AlertDescription.no_renegotiation: 'no_renegotiation',
  55.         AlertDescription.unknown_srp_username: 'unknown_srp_username',
  56.         AlertDescription.missing_srp_username: 'missing_srp_username' }
  57.  
  58.  
  59. class TLSLocalAlert(TLSAlert):
  60.     '''A TLS alert has been signalled by the local implementation.
  61.  
  62.     @type description: int
  63.     @ivar description: Set to one of the constants in
  64.     L{tlslite.constants.AlertDescription}
  65.  
  66.     @type level: int
  67.     @ivar level: Set to one of the constants in
  68.     L{tlslite.constants.AlertLevel}
  69.  
  70.     @type message: str
  71.     @ivar message: Description of what went wrong.
  72.     '''
  73.     
  74.     def __init__(self, alert, message = None):
  75.         self.description = alert.description
  76.         self.level = alert.level
  77.         self.message = message
  78.  
  79.     
  80.     def __str__(self):
  81.         alertStr = TLSAlert._descriptionStr.get(self.description)
  82.         if alertStr == None:
  83.             alertStr = str(self.description)
  84.         
  85.         if self.message:
  86.             return alertStr + ': ' + self.message
  87.         return alertStr
  88.  
  89.  
  90.  
  91. class TLSRemoteAlert(TLSAlert):
  92.     '''A TLS alert has been signalled by the remote implementation.
  93.  
  94.     @type description: int
  95.     @ivar description: Set to one of the constants in
  96.     L{tlslite.constants.AlertDescription}
  97.  
  98.     @type level: int
  99.     @ivar level: Set to one of the constants in
  100.     L{tlslite.constants.AlertLevel}
  101.     '''
  102.     
  103.     def __init__(self, alert):
  104.         self.description = alert.description
  105.         self.level = alert.level
  106.  
  107.     
  108.     def __str__(self):
  109.         alertStr = TLSAlert._descriptionStr.get(self.description)
  110.         if alertStr == None:
  111.             alertStr = str(self.description)
  112.         
  113.         return alertStr
  114.  
  115.  
  116.  
  117. class TLSAuthenticationError(TLSError):
  118.     """The handshake succeeded, but the other party's authentication
  119.     was inadequate.
  120.  
  121.     This exception will only be raised when a
  122.     L{tlslite.Checker.Checker} has been passed to a handshake function.
  123.     The Checker will be invoked once the handshake completes, and if
  124.     the Checker objects to how the other party authenticated, a
  125.     subclass of this exception will be raised.
  126.     """
  127.     pass
  128.  
  129.  
  130. class TLSNoAuthenticationError(TLSAuthenticationError):
  131.     '''The Checker was expecting the other party to authenticate with a
  132.     certificate chain, but this did not occur.'''
  133.     pass
  134.  
  135.  
  136. class TLSAuthenticationTypeError(TLSAuthenticationError):
  137.     '''The Checker was expecting the other party to authenticate with a
  138.     different type of certificate chain.'''
  139.     pass
  140.  
  141.  
  142. class TLSFingerprintError(TLSAuthenticationError):
  143.     '''The Checker was expecting the other party to authenticate with a
  144.     certificate chain that matches a different fingerprint.'''
  145.     pass
  146.  
  147.  
  148. class TLSAuthorizationError(TLSAuthenticationError):
  149.     '''The Checker was expecting the other party to authenticate with a
  150.     certificate chain that has a different authorization.'''
  151.     pass
  152.  
  153.  
  154. class TLSValidationError(TLSAuthenticationError):
  155.     """The Checker has determined that the other party's certificate
  156.     chain is invalid."""
  157.     pass
  158.  
  159.  
  160. class TLSFaultError(TLSError):
  161.     """The other party responded incorrectly to an induced fault.
  162.  
  163.     This exception will only occur during fault testing, when a
  164.     TLSConnection's fault variable is set to induce some sort of
  165.     faulty behavior, and the other party doesn't respond appropriately.
  166.     """
  167.     pass
  168.  
  169.